<?php

require_once "RegistrationView.php";
require_once "RegistrationHandler.php";
require_once "Database/Database.php";

class RegistrationController
{
	public static function DoControl(Database $db)
	{
		$rw = new RegistrationView();
		$rh = new RegistrationHandler($db);
		
		$return = "";
		$return .= $rw->DoHeader();
		$return .= $rw->DoRegistrationBox();
		
		if ($rw->TriedToAddUser())
			if ($rh->PasswordMatches($rw->GetPassword(), $rw->GetPasswordConfirmation()))
			{
				if (!$rh->AddUser($rw->GetUsername(), $rw->GetPassword()))
					$return .= "fail";
				else
					$return .= "success";
			}
			else
				$return .= "Passwords doesnt match";
		
		if ($rw->TriedToRemoveUser())
			if (!$rh->RemoveUser($rw->GetUsername()))
				$return .= "fail";
			else
				$return .= "success";
			
		return $return;
	}
}